package com.grandbroad.eim.ui.fragment.live;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.easy.west.westclient.api.base.bean.VodBean;
import com.easy.west.westclient.api.hotvod.bean.VodList;
import com.easy.west.westclient.api.hotvod.event.GetHotVodListEvent;
import com.grandbroad.eim.R;
import com.grandbroad.eim.adapter.VideoDesAdapter;
import com.grandbroad.eim.app.MyApplication;
import com.grandbroad.eim.base.BaseFragment;
import com.grandbroad.eim.base.BaseRecyclerview;
import com.grandbroad.eim.entry.LiveRoomBean;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class LiveDesFragment extends BaseRecyclerview {
    private Bundle bundle;
    private LiveRoomBean liveRoomBean;
    private VideoDesAdapter desAdapter;

    @Override
    protected boolean setEventOpen() {
        return true;
    }

    @Override
    protected void initRecyclerview(RecyclerView recyclerView) {
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.setAdapter(desAdapter);
        baseRecyclerview.setRefreshing(true);
        baseRecyclerview.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                getRecommendVod();
            }
        });
    }


    @Override
    protected void loadData() {
        //getNet
        getRecommendVod();
        bundle = getArguments();
        liveRoomBean = (LiveRoomBean) bundle.getSerializable("bean");
        desAdapter = new VideoDesAdapter((AppCompatActivity) getActivity());
        desAdapter.setThisbean(liveRoomBean);
        desAdapter.notifyDataSetChanged();

    }

    private void getRecommendVod() {
        MyApplication.getMoleclient().getHotVod();
    }

    /**
     * 获取热门列表
     * @param eva
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getHotVod(GetHotVodListEvent eva)
    {
        if (eva.isOk())
        {
            VodList list = eva.getBean();
            if (list.getStatus()==1)
            {
                stopRefresh();
                desAdapter.setVodBeanList(list.getData());
                desAdapter.notifyDataSetChanged();
            }
        }
        else {
            stopRefresh();
        }
    }
}